import Cookies from "js-cookie";

export default {
  namespaced: true,
  state: {
    isCollapse: false,
    sideWidth: "220",
    layoutSize: Cookies.get("layoutSize") || "default",
  },
  mutations: {
    TOGGLE_SIDEBAR: (state) => {
      if (state.isCollapse || state.isCollapse === undefined) {
        state.sideWidth = "64";
      } else {
        state.sideWidth = "220";
      }
    },
    TOGGLE_HAMBURGER: (state) => {
      state.isCollapse = !state.isCollapse;
    },
    SET_LAYOUT_SIZE: (state, layoutSize) => {
      state.size = layoutSize;
      Cookies.set("layoutSize", layoutSize);
    },
  },
  actions: {
    toggleSidebar({ commit }) {
      commit("TOGGLE_SIDEBAR");
    },
    toggleHamburger({ commit }) {
      commit("TOGGLE_HAMBURGER");
    },
    setLayoutSize({ commit }, size) {
      commit("SET_LAYOUT_SIZE", size);
    },
  },
};
